{% extends "base.html" %}

{% block title %}配置参数 - 长者照护计划系统{% endblock %}

{% block page_title %}配置参数{% endblock %}

{% block extra_css %}
<style>
    .param-section {
        margin-bottom: 20px;
        padding: 15px;
        border: 1px solid #dee2e6;
        border-radius: 5px;
        background-color: #f8f9fa;
    }

    .param-table {
        width: 100%;
        margin-bottom: 1rem;
    }

    .param-table th, .param-table td {
        padding: 0.5rem;
        border: 1px solid #dee2e6;
    }

    .param-table th {
        background-color: #f8f9fa;
    }

    .param-description {
        font-size: 0.9rem;
        color: #6c757d;
    }

    .json-display {
        background-color: #f8f9fa;
        border: 1px solid #dee2e6;
        border-radius: 4px;
        padding: 10px;
        font-family: monospace;
        white-space: pre-wrap;
        max-height: 500px;
        overflow-y: auto;
    }

    .editable {
        cursor: pointer;
        position: relative;
    }

    .editable:hover {
        background-color: #e9ecef;
    }

    .editable::after {
        content: "\f044";
        font-family: "Font Awesome 5 Free";
        font-weight: 900;
        position: absolute;
        right: 5px;
        top: 50%;
        transform: translateY(-50%);
        opacity: 0;
        transition: opacity 0.2s;
    }

    .editable:hover::after {
        opacity: 1;
    }

    .edit-form {
        display: none;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: #fff;
        z-index: 10;
        padding: 5px;
    }

    .edit-form input, .edit-form select {
        width: 100%;
        height: 100%;
        border: 1px solid #007bff;
        padding: 5px;
        border-radius: 3px;
    }

    .edit-form .btn-group {
        position: absolute;
        right: 5px;
        top: 50%;
        transform: translateY(-50%);
    }

    .edit-form .btn {
        padding: 0.1rem 0.3rem;
        font-size: 0.8rem;
    }

    .toast-container {
        position: fixed;
        top: 20px;
        right: 20px;
        z-index: 1000;
    }
</style>
{% endblock %}

{% block content %}
<div class="toast-container"></div>

<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-header">
                <h5 class="card-title">配置参数说明</h5>
            </div>
            <div class="card-body">
                <p>本页面展示系统的全局配置参数，包括算法参数、班次配置、三班制排班参数等。</p>
                <p>这些参数用于控制系统的行为和算法的执行。</p>
                <p>点击参数值可以进行编辑，编辑后的参数会立即保存到配置文件中，并影响接口的行为。</p>
                <div class="alert alert-info">
                    <i class="fas fa-info-circle"></i> 提示：修改参数后，系统会自动重新加载配置文件，无需重启应用。
                </div>
            </div>
        </div>
    </div>
</div>

<div class="row mt-4">
    <div class="col-md-12">
        <ul class="nav nav-tabs" id="paramTabs" role="tablist">
            <li class="nav-item" role="presentation">
                <button class="nav-link active" id="general-tab" data-bs-toggle="tab" data-bs-target="#general" type="button" role="tab">通用参数</button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="shift-config-tab" data-bs-toggle="tab" data-bs-target="#shift-config" type="button" role="tab">班次配置</button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="three-shift-tab" data-bs-toggle="tab" data-bs-target="#three-shift" type="button" role="tab">三班制参数</button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="shift-control-tab" data-bs-toggle="tab" data-bs-target="#shift-control" type="button" role="tab">班制控制</button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="shift-mode-tab" data-bs-toggle="tab" data-bs-target="#shift-mode" type="button" role="tab">班制模式</button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="rest-time-tab" data-bs-toggle="tab" data-bs-target="#rest-time" type="button" role="tab">休息时间</button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="json-tab" data-bs-toggle="tab" data-bs-target="#json" type="button" role="tab">JSON格式</button>
            </li>
        </ul>

        <div class="tab-content" id="paramTabsContent">
            <div class="tab-pane fade show active" id="general" role="tabpanel">
                <div class="param-section mt-3">
                    <h5>通用参数</h5>
                    <table class="table param-table">
                        <thead>
                            <tr>
                                <th>参数名</th>
                                <th>值</th>
                                <th>说明</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>client_num</td>
                                <td class="editable" data-param-type="params" data-param-name="client_num">
                                    <span class="param-value">{{ params.client_num }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ params.client_num }}">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>老人数量上限</td>
                            </tr>
                            <tr>
                                <td>caregiver_num</td>
                                <td class="editable" data-param-type="params" data-param-name="caregiver_num">
                                    <span class="param-value">{{ params.caregiver_num }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ params.caregiver_num }}">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>护理人员数量上限</td>
                            </tr>
                            <tr>
                                <td>time_slots_per_day</td>
                                <td class="editable" data-param-type="params" data-param-name="time_slots_per_day">
                                    <span class="param-value">{{ params.time_slots_per_day }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ params.time_slots_per_day }}">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>一天中的时间槽数量</td>
                            </tr>
                            <tr>
                                <td>time_interval_minutes</td>
                                <td class="editable" data-param-type="params" data-param-name="time_interval_minutes">
                                    <span class="param-value">{{ params.time_interval_minutes }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ params.time_interval_minutes }}">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>每个时间槽的分钟数</td>
                            </tr>
                        </tbody>
                    </table>
                </div>

                <div class="param-section">
                    <h5>算法参数</h5>
                    <table class="table param-table">
                        <thead>
                            <tr>
                                <th>参数名</th>
                                <th>值</th>
                                <th>说明</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>population_size</td>
                                <td class="editable" data-param-type="params" data-param-name="population_size">
                                    <span class="param-value">{{ params.population_size }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ params.population_size }}" min="1" max="1000">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>遗传算法种群大小</td>
                            </tr>
                            <tr>
                                <td>crossover_rate</td>
                                <td class="editable" data-param-type="params" data-param-name="crossover_rate">
                                    <span class="param-value">{{ params.crossover_rate }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ params.crossover_rate }}" step="0.01" min="0" max="1">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>交叉率</td>
                            </tr>
                            <tr>
                                <td>mutation_rate</td>
                                <td class="editable" data-param-type="params" data-param-name="mutation_rate">
                                    <span class="param-value">{{ params.mutation_rate }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ params.mutation_rate }}" step="0.01" min="0" max="1">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>变异率</td>
                            </tr>
                            <tr>
                                <td>phenotype_limit</td>
                                <td class="editable" data-param-type="params" data-param-name="phenotype_limit">
                                    <span class="param-value">{{ params.phenotype_limit }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ params.phenotype_limit }}" min="1">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>最大迭代代数</td>
                            </tr>
                            <tr>
                                <td>elimination_size</td>
                                <td class="editable" data-param-type="params" data-param-name="elimination_size">
                                    <span class="param-value">{{ params.elimination_size }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ params.elimination_size }}" min="0">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>每代淘汰数量</td>
                            </tr>
                            <tr>
                                <td>initial_temperature</td>
                                <td class="editable" data-param-type="params" data-param-name="initial_temperature">
                                    <span class="param-value">{{ params.initial_temperature }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ params.initial_temperature }}" min="0">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>模拟退火初始温度</td>
                            </tr>
                            <tr>
                                <td>cooling_rate</td>
                                <td class="editable" data-param-type="params" data-param-name="cooling_rate">
                                    <span class="param-value">{{ params.cooling_rate }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ params.cooling_rate }}" step="0.01" min="0" max="1">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>温度冷却率</td>
                            </tr>
                        </tbody>
                    </table>
                </div>

                <div class="param-section">
                    <h5>权重参数</h5>
                    <table class="table param-table">
                        <thead>
                            <tr>
                                <th>参数名</th>
                                <th>值</th>
                                <th>说明</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>caregiver_availability_weight</td>
                                <td class="editable" data-param-type="params" data-param-name="caregiver_availability_weight">
                                    <span class="param-value">{{ params.caregiver_availability_weight }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ params.caregiver_availability_weight }}" step="0.1" min="0" max="1">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>护理员可用性在适应度计算中的权重</td>
                            </tr>
                            <tr>
                                <td>scheduling_conflict_penalty</td>
                                <td class="editable" data-param-type="params" data-param-name="scheduling_conflict_penalty">
                                    <span class="param-value">{{ params.scheduling_conflict_penalty }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ params.scheduling_conflict_penalty }}" min="0">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>调度冲突的惩罚值</td>
                            </tr>
                            <tr>
                                <td>unassigned_slot_penalty</td>
                                <td class="editable" data-param-type="params" data-param-name="unassigned_slot_penalty">
                                    <span class="param-value">{{ params.unassigned_slot_penalty }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ params.unassigned_slot_penalty }}" min="0">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>未分配时间段的惩罚值</td>
                            </tr>
                        </tbody>
                    </table>
                </div>

                <div class="param-section">
                    <h5>强化学习参数</h5>
                    <table class="table param-table">
                        <thead>
                            <tr>
                                <th>参数名</th>
                                <th>值</th>
                                <th>说明</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>rl_learning_rate</td>
                                <td class="editable" data-param-type="params" data-param-name="rl_learning_rate">
                                    <span class="param-value">{{ params.rl_learning_rate }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ params.rl_learning_rate }}" step="0.01" min="0" max="1">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>学习率</td>
                            </tr>
                            <tr>
                                <td>rl_discount_factor</td>
                                <td class="editable" data-param-type="params" data-param-name="rl_discount_factor">
                                    <span class="param-value">{{ params.rl_discount_factor }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ params.rl_discount_factor }}" step="0.01" min="0" max="1">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>折扣因子</td>
                            </tr>
                            <tr>
                                <td>rl_exploration_rate</td>
                                <td class="editable" data-param-type="params" data-param-name="rl_exploration_rate">
                                    <span class="param-value">{{ params.rl_exploration_rate }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ params.rl_exploration_rate }}" step="0.01" min="0" max="1">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>探索率</td>
                            </tr>
                            <tr>
                                <td>rl_exploration_decay</td>
                                <td class="editable" data-param-type="params" data-param-name="rl_exploration_decay">
                                    <span class="param-value">{{ params.rl_exploration_decay }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ params.rl_exploration_decay }}" step="0.001" min="0" max="1">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>探索率衰减</td>
                            </tr>
                            <tr>
                                <td>rl_min_exploration_rate</td>
                                <td class="editable" data-param-type="params" data-param-name="rl_min_exploration_rate">
                                    <span class="param-value">{{ params.rl_min_exploration_rate }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ params.rl_min_exploration_rate }}" step="0.01" min="0" max="1">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>最小探索率</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="tab-pane fade" id="shift-config" role="tabpanel">
                <div class="param-section mt-3">
                    <h5>班次配置</h5>
                    <table class="table param-table">
                        <thead>
                            <tr>
                                <th>班次</th>
                                <th>名称</th>
                                <th>开始时间</th>
                                <th>结束时间</th>
                                <th>排序</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr id="shift1Section">
                                <td>班次1（早班）</td>
                                <td class="editable" data-param-type="shift_config" data-param-name="morning_shift.name">
                                    <span class="param-value">{{ shift_config.morning_shift.name }}</span>
                                    <div class="edit-form">
                                        <input type="text" class="form-control" value="{{ shift_config.morning_shift.name }}">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_config" data-param-name="morning_shift.start_time">
                                    <span class="param-value">{{ shift_config.morning_shift.start_time }}</span>
                                    <div class="edit-form">
                                        <input type="time" class="form-control" value="{{ shift_config.morning_shift.start_time }}" pattern="[0-9]{2}:[0-9]{2}">
                                        <small class="form-text text-muted">格式: HH:MM (24小时制)</small>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_config" data-param-name="morning_shift.end_time">
                                    <span class="param-value">{{ shift_config.morning_shift.end_time }}</span>
                                    <div class="edit-form">
                                        <input type="time" class="form-control" value="{{ shift_config.morning_shift.end_time }}" pattern="[0-9]{2}:[0-9]{2}">
                                        <small class="form-text text-muted">格式: HH:MM (24小时制)</small>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_config" data-param-name="morning_shift.order">
                                    <span class="param-value">{{ shift_config.morning_shift.order }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ shift_config.morning_shift.order }}" min="1" max="3">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr id="shift2Section">
                                <td>班次2（中班）</td>
                                <td class="editable" data-param-type="shift_config" data-param-name="afternoon_shift.name">
                                    <span class="param-value">{{ shift_config.afternoon_shift.name }}</span>
                                    <div class="edit-form">
                                        <input type="text" class="form-control" value="{{ shift_config.afternoon_shift.name }}">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_config" data-param-name="afternoon_shift.start_time">
                                    <span class="param-value">{{ shift_config.afternoon_shift.start_time }}</span>
                                    <div class="edit-form">
                                        <input type="time" class="form-control" value="{{ shift_config.afternoon_shift.start_time }}" pattern="[0-9]{2}:[0-9]{2}">
                                        <small class="form-text text-muted">格式: HH:MM (24小时制)</small>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_config" data-param-name="afternoon_shift.end_time">
                                    <span class="param-value">{{ shift_config.afternoon_shift.end_time }}</span>
                                    <div class="edit-form">
                                        <input type="time" class="form-control" value="{{ shift_config.afternoon_shift.end_time }}" pattern="[0-9]{2}:[0-9]{2}">
                                        <small class="form-text text-muted">格式: HH:MM (24小时制)</small>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_config" data-param-name="afternoon_shift.order">
                                    <span class="param-value">{{ shift_config.afternoon_shift.order }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ shift_config.afternoon_shift.order }}" min="1" max="3">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr id="shift3Section">
                                <td>班次3（夜班）</td>
                                <td class="editable" data-param-type="shift_config" data-param-name="night_shift.name">
                                    <span class="param-value">{{ shift_config.night_shift.name }}</span>
                                    <div class="edit-form">
                                        <input type="text" class="form-control" value="{{ shift_config.night_shift.name }}">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_config" data-param-name="night_shift.start_time">
                                    <span class="param-value">{{ shift_config.night_shift.start_time }}</span>
                                    <div class="edit-form">
                                        <input type="time" class="form-control" value="{{ shift_config.night_shift.start_time }}" pattern="[0-9]{2}:[0-9]{2}">
                                        <small class="form-text text-muted">格式: HH:MM (24小时制)</small>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_config" data-param-name="night_shift.end_time">
                                    <span class="param-value">{{ shift_config.night_shift.end_time }}</span>
                                    <div class="edit-form">
                                        <input type="time" class="form-control" value="{{ shift_config.night_shift.end_time }}" pattern="[0-9]{2}:[0-9]{2}">
                                        <small class="form-text text-muted">格式: HH:MM (24小时制)</small>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_config" data-param-name="night_shift.order">
                                    <span class="param-value">{{ shift_config.night_shift.order }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ shift_config.night_shift.order }}" min="1" max="3">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="tab-pane fade" id="three-shift" role="tabpanel">
                <div class="param-section mt-3">
                    <h5>三班制排班参数</h5>
                    <table class="table param-table">
                        <thead>
                            <tr>
                                <th>参数名</th>
                                <th>值</th>
                                <th>说明</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>schedule_type</td>
                                <td class="editable" data-param-type="three_shift_params" data-param-name="schedule_type">
                                    <span class="param-value">{{ three_shift_params.schedule_type }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" value="{{ three_shift_params.schedule_type }}">
                                            <option value="1" {% if three_shift_params.schedule_type == 1 %}selected{% endif %}>1 (按天)</option>
                                            <option value="2" {% if three_shift_params.schedule_type == 2 %}selected{% endif %}>2 (按周)</option>
                                            <option value="3" {% if three_shift_params.schedule_type == 3 %}selected{% endif %}>3 (按月)</option>
                                            <option value="4" {% if three_shift_params.schedule_type == 4 %}selected{% endif %}>4 (按季度)</option>
                                            <option value="5" {% if three_shift_params.schedule_type == 5 %}selected{% endif %}>5 (按年)</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>排班类型: 1(按天), 2(按周), 3(按月), 4(按季度), 5(按年)</td>
                            </tr>
                            <tr>
                                <td>start_date</td>
                                <td class="editable" data-param-type="three_shift_params" data-param-name="start_date">
                                    <span class="param-value">{{ three_shift_params.start_date }}</span>
                                    <div class="edit-form">
                                        <input type="date" class="form-control" value="{{ three_shift_params.start_date }}" pattern="\d{4}-\d{2}-\d{2}">
                                        <small class="form-text text-muted">格式: YYYY-MM-DD</small>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>开始日期</td>
                            </tr>
                            <tr>
                                <td>num_days</td>
                                <td class="editable" data-param-type="three_shift_params" data-param-name="num_days">
                                    <span class="param-value">{{ three_shift_params.num_days }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ three_shift_params.num_days }}" min="1" max="365">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>排班天数，当schedule_type为1(按天)时有效</td>
                            </tr>
                            <tr>
                                <td>shift_start_time</td>
                                <td class="editable" data-param-type="three_shift_params" data-param-name="shift_start_time">
                                    <span class="param-value">{{ three_shift_params.shift_start_time }}</span>
                                    <div class="edit-form">
                                        <input type="time" class="form-control" value="{{ three_shift_params.shift_start_time }}" pattern="[0-9]{2}:[0-9]{2}">
                                        <small class="form-text text-muted">格式: HH:MM (24小时制)</small>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>班次开始时间</td>
                            </tr>
                            <tr>
                                <td>shift_mode</td>
                                <td class="editable" data-param-type="three_shift_params" data-param-name="shift_mode">
                                    <span class="param-value">{{ three_shift_params.shift_mode }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" value="{{ three_shift_params.shift_mode }}">
                                            <option value="1" {% if three_shift_params.shift_mode == 1 %}selected{% endif %}>1 (一班制)</option>
                                            <option value="2" {% if three_shift_params.shift_mode == 2 %}selected{% endif %}>2 (二班制)</option>
                                            <option value="3" {% if three_shift_params.shift_mode == 3 %}selected{% endif %}>3 (三班制)</option>
                                            <option value="4" {% if three_shift_params.shift_mode == 4 %}selected{% endif %}>4 (自定义班制)</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>班制模式：1(一班制), 2(二班制), 3(三班制), 4(自定义班制)</td>
                            </tr>
                            <tr>
                                <td>time_slots_per_day</td>
                                <td class="editable" data-param-type="three_shift_params" data-param-name="time_slots_per_day">
                                    <span class="param-value">{{ three_shift_params.time_slots_per_day }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ three_shift_params.time_slots_per_day }}" min="1" max="144">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>一天中的时间槽数量</td>
                            </tr>
                            <tr>
                                <td>time_interval_minutes</td>
                                <td class="editable" data-param-type="three_shift_params" data-param-name="time_interval_minutes">
                                    <span class="param-value">{{ three_shift_params.time_interval_minutes }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ three_shift_params.time_interval_minutes }}" min="10" max="60" step="5">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>每个时间槽的分钟数</td>
                            </tr>
                            <tr>
                                <td>day_segments</td>
                                <td class="editable" data-param-type="three_shift_params" data-param-name="day_segments">
                                    <span class="param-value">{{ three_shift_params.day_segments }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" value="{{ three_shift_params.day_segments }}">
                                            <option value="1" {% if three_shift_params.day_segments == 1 %}selected{% endif %}>1</option>
                                            <option value="2" {% if three_shift_params.day_segments == 2 %}selected{% endif %}>2</option>
                                            <option value="3" {% if three_shift_params.day_segments == 3 %}selected{% endif %}>3</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>一天分几段（可选：1，2，3）</td>
                            </tr>
                            <tr>
                                <td>param_priority_enabled</td>
                                <td class="editable" data-param-type="three_shift_params" data-param-name="param_priority_enabled">
                                    <span class="param-value">{{ three_shift_params.param_priority_enabled }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" value="{{ three_shift_params.param_priority_enabled }}">
                                            <option value="true" {% if three_shift_params.param_priority_enabled %}selected{% endif %}>True</option>
                                            <option value="false" {% if not three_shift_params.param_priority_enabled %}selected{% endif %}>False</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>传参优先级开关</td>
                            </tr>
                            <tr>
                                <td>allow_cross_day</td>
                                <td class="editable" data-param-type="three_shift_params" data-param-name="allow_cross_day">
                                    <span class="param-value">{{ three_shift_params.allow_cross_day }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" value="{{ three_shift_params.allow_cross_day }}">
                                            <option value="true" {% if three_shift_params.allow_cross_day %}selected{% endif %}>True</option>
                                            <option value="false" {% if not three_shift_params.allow_cross_day %}selected{% endif %}>False</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>是否允许跨天</td>
                            </tr>
                            <tr>
                                <td>use_fixed_shift_times</td>
                                <td class="editable" data-param-type="three_shift_params" data-param-name="use_fixed_shift_times">
                                    <span class="param-value">{{ three_shift_params.use_fixed_shift_times }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" value="{{ three_shift_params.use_fixed_shift_times }}">
                                            <option value="true" {% if three_shift_params.use_fixed_shift_times %}selected{% endif %}>True</option>
                                            <option value="false" {% if not three_shift_params.use_fixed_shift_times %}selected{% endif %}>False</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>是否使用固定班次时间</td>
                            </tr>
                        </tbody>
                    </table>
                </div>

                <div class="param-section">
                    <h5>自动排班参数</h5>
                    <table class="table param-table">
                        <thead>
                            <tr>
                                <th>参数名</th>
                                <th>值</th>
                                <th>说明</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>auto_schedule_enabled</td>
                                <td class="editable" data-param-type="three_shift_params" data-param-name="auto_schedule_enabled">
                                    <span class="param-value">{{ three_shift_params.auto_schedule_enabled }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" value="{{ three_shift_params.auto_schedule_enabled }}">
                                            <option value="true" {% if three_shift_params.auto_schedule_enabled %}selected{% endif %}>True</option>
                                            <option value="false" {% if not three_shift_params.auto_schedule_enabled %}selected{% endif %}>False</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>是否启用自动排班功能</td>
                            </tr>
                            <tr>
                                <td>auto_schedule_immediate</td>
                                <td class="editable" data-param-type="three_shift_params" data-param-name="auto_schedule_immediate">
                                    <span class="param-value">{{ three_shift_params.auto_schedule_immediate }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" value="{{ three_shift_params.auto_schedule_immediate }}">
                                            <option value="true" {% if three_shift_params.auto_schedule_immediate %}selected{% endif %}>True</option>
                                            <option value="false" {% if not three_shift_params.auto_schedule_immediate %}selected{% endif %}>False</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>是否在接口调用时立即执行一次排班</td>
                            </tr>
                            <tr>
                                <td>auto_schedule_minutes</td>
                                <td class="editable" data-param-type="three_shift_params" data-param-name="auto_schedule_minutes">
                                    <span class="param-value">{{ three_shift_params.auto_schedule_minutes }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ three_shift_params.auto_schedule_minutes }}" min="1" max="1440">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>自动排班间隔分钟数</td>
                            </tr>
                            <tr>
                                <td>auto_schedule_generate_care_timeline</td>
                                <td class="editable" data-param-type="three_shift_params" data-param-name="auto_schedule_generate_care_timeline">
                                    <span class="param-value">{{ three_shift_params.auto_schedule_generate_care_timeline }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" value="{{ three_shift_params.auto_schedule_generate_care_timeline }}">
                                            <option value="true" {% if three_shift_params.auto_schedule_generate_care_timeline %}selected{% endif %}>True</option>
                                            <option value="false" {% if not three_shift_params.auto_schedule_generate_care_timeline %}selected{% endif %}>False</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>自动排班是否生成照护时间线</td>
                            </tr>
                            <tr>
                                <td>auto_schedule_shift_mode</td>
                                <td class="editable" data-param-type="three_shift_params" data-param-name="auto_schedule_shift_mode">
                                    <span class="param-value">{{ three_shift_params.auto_schedule_shift_mode }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" value="{{ three_shift_params.auto_schedule_shift_mode }}">
                                            <option value="1" {% if three_shift_params.auto_schedule_shift_mode == 1 %}selected{% endif %}>1 (一班制)</option>
                                            <option value="2" {% if three_shift_params.auto_schedule_shift_mode == 2 %}selected{% endif %}>2 (二班制)</option>
                                            <option value="3" {% if three_shift_params.auto_schedule_shift_mode == 3 %}selected{% endif %}>3 (三班制)</option>
                                            <option value="4" {% if three_shift_params.auto_schedule_shift_mode == 4 %}selected{% endif %}>4 (自定义班制)</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>自动排班使用的班制模式</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="tab-pane fade" id="shift-control" role="tabpanel">
                <div class="param-section mt-3">
                    <h5>班制控制参数</h5>
                    <table class="table param-table">
                        <thead>
                            <tr>
                                <th>参数名</th>
                                <th>值</th>
                                <th>说明</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>enabled_shifts</td>
                                <td class="editable" data-param-type="shift_control" data-param-name="enabled_shifts">
                                    <span class="param-value">{{ shift_control.enabled_shifts|join(', ') }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" multiple name="enabled_shifts">
                                            <option value="morning_shift" {% if 'morning_shift' in shift_control.enabled_shifts %}selected{% endif %}>班次1 (早班)</option>
                                            <option value="afternoon_shift" {% if 'afternoon_shift' in shift_control.enabled_shifts %}selected{% endif %}>班次2 (中班)</option>
                                            <option value="night_shift" {% if 'night_shift' in shift_control.enabled_shifts %}selected{% endif %}>班次3 (夜班)</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>启用的班次</td>
                            </tr>
                            <tr>
                                <td>min_shifts_per_day</td>
                                <td class="editable" data-param-type="shift_control" data-param-name="min_shifts_per_day">
                                    <span class="param-value">{{ shift_control.min_shifts_per_day }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ shift_control.min_shifts_per_day }}" min="1" max="3">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>每天最少需要的班次数</td>
                            </tr>
                            <tr>
                                <td>max_shifts_per_day</td>
                                <td class="editable" data-param-type="shift_control" data-param-name="max_shifts_per_day">
                                    <span class="param-value">{{ shift_control.max_shifts_per_day }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ shift_control.max_shifts_per_day }}" min="1" max="3">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>每天最多允许的班次数</td>
                            </tr>
                            <tr>
                                <td>allow_empty_shifts</td>
                                <td class="editable" data-param-type="shift_control" data-param-name="allow_empty_shifts">
                                    <span class="param-value">{{ shift_control.allow_empty_shifts }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" value="{{ shift_control.allow_empty_shifts }}">
                                            <option value="true" {% if shift_control.allow_empty_shifts %}selected{% endif %}>True</option>
                                            <option value="false" {% if not shift_control.allow_empty_shifts %}selected{% endif %}>False</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>是否允许某些班次为空（没有护理员）</td>
                            </tr>
                            <tr>
                                <td>shift_sort_method</td>
                                <td class="editable" data-param-type="shift_control" data-param-name="shift_sort_method">
                                    <span class="param-value">{{ shift_control.shift_sort_method }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" value="{{ shift_control.shift_sort_method }}">
                                            <option value="time" {% if shift_control.shift_sort_method == 'time' %}selected{% endif %}>time</option>
                                            <option value="order" {% if shift_control.shift_sort_method == 'order' %}selected{% endif %}>order</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>班次排序方式: 'time' 或 'order'</td>
                            </tr>
                            <tr>
                                <td>auto_adjust_time</td>
                                <td class="editable" data-param-type="shift_control" data-param-name="auto_adjust_time">
                                    <span class="param-value">{{ shift_control.auto_adjust_time }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" value="{{ shift_control.auto_adjust_time }}">
                                            <option value="true" {% if shift_control.auto_adjust_time %}selected{% endif %}>True</option>
                                            <option value="false" {% if not shift_control.auto_adjust_time %}selected{% endif %}>False</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>是否自动调整班次时间以覆盖24小时</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="tab-pane fade" id="shift-mode" role="tabpanel">
                <div class="param-section mt-3">
                    <h5>班制模式配置</h5>
                    <table class="table param-table">
                        <thead>
                            <tr>
                                <th>模式</th>
                                <th>名称</th>
                                <th>班次</th>
                                <th>每班时长</th>
                                <th>说明</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>一班制</td>
                                <td class="editable" data-param-type="shift_mode_config" data-param-name="one_shift.name">
                                    <span class="param-value">{{ shift_mode_config.one_shift.name }}</span>
                                    <div class="edit-form">
                                        <input type="text" class="form-control" value="{{ shift_mode_config.one_shift.name }}">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_mode_config" data-param-name="one_shift.shifts">
                                    <span class="param-value">{{ shift_mode_config.one_shift.shifts|join(', ') }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" multiple name="one_shift_shifts">
                                            <option value="morning_shift" {% if 'morning_shift' in shift_mode_config.one_shift.shifts %}selected{% endif %}>班次1 (早班)</option>
                                            <option value="afternoon_shift" {% if 'afternoon_shift' in shift_mode_config.one_shift.shifts %}selected{% endif %}>班次2 (中班)</option>
                                            <option value="night_shift" {% if 'night_shift' in shift_mode_config.one_shift.shifts %}selected{% endif %}>班次3 (夜班)</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_mode_config" data-param-name="one_shift.hours_per_shift">
                                    <span class="param-value">{{ shift_mode_config.one_shift.hours_per_shift }}小时</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ shift_mode_config.one_shift.hours_per_shift }}" min="1" max="24">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_mode_config" data-param-name="one_shift.description">
                                    <span class="param-value">{{ shift_mode_config.one_shift.description }}</span>
                                    <div class="edit-form">
                                        <input type="text" class="form-control" value="{{ shift_mode_config.one_shift.description }}">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>二班制</td>
                                <td class="editable" data-param-type="shift_mode_config" data-param-name="two_shift.name">
                                    <span class="param-value">{{ shift_mode_config.two_shift.name }}</span>
                                    <div class="edit-form">
                                        <input type="text" class="form-control" value="{{ shift_mode_config.two_shift.name }}">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_mode_config" data-param-name="two_shift.shifts">
                                    <span class="param-value">{{ shift_mode_config.two_shift.shifts|join(', ') }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" multiple name="two_shift_shifts">
                                            <option value="morning_shift" {% if 'morning_shift' in shift_mode_config.two_shift.shifts %}selected{% endif %}>班次1 (早班)</option>
                                            <option value="afternoon_shift" {% if 'afternoon_shift' in shift_mode_config.two_shift.shifts %}selected{% endif %}>班次2 (中班)</option>
                                            <option value="night_shift" {% if 'night_shift' in shift_mode_config.two_shift.shifts %}selected{% endif %}>班次3 (夜班)</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_mode_config" data-param-name="two_shift.hours_per_shift">
                                    <span class="param-value">{{ shift_mode_config.two_shift.hours_per_shift }}小时</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ shift_mode_config.two_shift.hours_per_shift }}" min="1" max="24">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_mode_config" data-param-name="two_shift.description">
                                    <span class="param-value">{{ shift_mode_config.two_shift.description }}</span>
                                    <div class="edit-form">
                                        <input type="text" class="form-control" value="{{ shift_mode_config.two_shift.description }}">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>三班制</td>
                                <td class="editable" data-param-type="shift_mode_config" data-param-name="three_shift.name">
                                    <span class="param-value">{{ shift_mode_config.three_shift.name }}</span>
                                    <div class="edit-form">
                                        <input type="text" class="form-control" value="{{ shift_mode_config.three_shift.name }}">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_mode_config" data-param-name="three_shift.shifts">
                                    <span class="param-value">{{ shift_mode_config.three_shift.shifts|join(', ') }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" multiple name="three_shift_shifts">
                                            <option value="morning_shift" {% if 'morning_shift' in shift_mode_config.three_shift.shifts %}selected{% endif %}>班次1 (早班)</option>
                                            <option value="afternoon_shift" {% if 'afternoon_shift' in shift_mode_config.three_shift.shifts %}selected{% endif %}>班次2 (中班)</option>
                                            <option value="night_shift" {% if 'night_shift' in shift_mode_config.three_shift.shifts %}selected{% endif %}>班次3 (夜班)</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_mode_config" data-param-name="three_shift.hours_per_shift">
                                    <span class="param-value">{{ shift_mode_config.three_shift.hours_per_shift }}小时</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ shift_mode_config.three_shift.hours_per_shift }}" min="1" max="24">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_mode_config" data-param-name="three_shift.description">
                                    <span class="param-value">{{ shift_mode_config.three_shift.description }}</span>
                                    <div class="edit-form">
                                        <input type="text" class="form-control" value="{{ shift_mode_config.three_shift.description }}">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>自定义班制</td>
                                <td class="editable" data-param-type="shift_mode_config" data-param-name="custom.name">
                                    <span class="param-value">{{ shift_mode_config.custom.name }}</span>
                                    <div class="edit-form">
                                        <input type="text" class="form-control" value="{{ shift_mode_config.custom.name }}">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_mode_config" data-param-name="custom.shifts">
                                    <span class="param-value">{{ shift_mode_config.custom.shifts|join(', ') }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" multiple name="custom_shifts">
                                            <option value="morning_shift" {% if 'morning_shift' in shift_mode_config.custom.shifts %}selected{% endif %}>班次1 (早班)</option>
                                            <option value="afternoon_shift" {% if 'afternoon_shift' in shift_mode_config.custom.shifts %}selected{% endif %}>班次2 (中班)</option>
                                            <option value="night_shift" {% if 'night_shift' in shift_mode_config.custom.shifts %}selected{% endif %}>班次3 (夜班)</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_mode_config" data-param-name="custom.hours_per_shift">
                                    <span class="param-value">{{ shift_mode_config.custom.hours_per_shift or '动态计算' }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ shift_mode_config.custom.hours_per_shift or '' }}" min="0" max="24" placeholder="动态计算">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td class="editable" data-param-type="shift_mode_config" data-param-name="custom.description">
                                    <span class="param-value">{{ shift_mode_config.custom.description }}</span>
                                    <div class="edit-form">
                                        <input type="text" class="form-control" value="{{ shift_mode_config.custom.description }}">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="tab-pane fade" id="rest-time" role="tabpanel">
                <div class="param-section mt-3">
                    <h5>护理员休息时间控制参数</h5>
                    <table class="table param-table">
                        <thead>
                            <tr>
                                <th>参数名</th>
                                <th>值</th>
                                <th>说明</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>min_rest_between_shifts</td>
                                <td class="editable" data-param-type="rest_time_control" data-param-name="min_rest_between_shifts">
                                    <span class="param-value">{{ rest_time_control.min_rest_between_shifts }}小时</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ rest_time_control.min_rest_between_shifts }}" min="0" max="24">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>两个班次之间的最小休息时间</td>
                            </tr>
                            <tr>
                                <td>min_rest_after_night_shift</td>
                                <td class="editable" data-param-type="rest_time_control" data-param-name="min_rest_after_night_shift">
                                    <span class="param-value">{{ rest_time_control.min_rest_after_night_shift }}小时</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ rest_time_control.min_rest_after_night_shift }}" min="0" max="24">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>夜班后的最小休息时间</td>
                            </tr>
                            <tr>
                                <td>max_consecutive_shifts</td>
                                <td class="editable" data-param-type="rest_time_control" data-param-name="max_consecutive_shifts">
                                    <span class="param-value">{{ rest_time_control.max_consecutive_shifts }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ rest_time_control.max_consecutive_shifts }}" min="1" max="10">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>最大连续工作班次数</td>
                            </tr>
                            <tr>
                                <td>max_weekly_work_hours</td>
                                <td class="editable" data-param-type="rest_time_control" data-param-name="max_weekly_work_hours">
                                    <span class="param-value">{{ rest_time_control.max_weekly_work_hours }}小时</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ rest_time_control.max_weekly_work_hours }}" min="0" max="168">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>每周最大工作时间</td>
                            </tr>
                            <tr>
                                <td>max_weekly_night_shifts</td>
                                <td class="editable" data-param-type="rest_time_control" data-param-name="max_weekly_night_shifts">
                                    <span class="param-value">{{ rest_time_control.max_weekly_night_shifts }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ rest_time_control.max_weekly_night_shifts }}" min="0" max="7">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>每周最大夜班次数</td>
                            </tr>
                            <tr>
                                <td>require_weekend_rest</td>
                                <td class="editable" data-param-type="rest_time_control" data-param-name="require_weekend_rest">
                                    <span class="param-value">{{ rest_time_control.require_weekend_rest }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" value="{{ rest_time_control.require_weekend_rest }}">
                                            <option value="true" {% if rest_time_control.require_weekend_rest %}selected{% endif %}>True</option>
                                            <option value="false" {% if not rest_time_control.require_weekend_rest %}selected{% endif %}>False</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>是否要求周末至少休息一天</td>
                            </tr>
                            <tr>
                                <td>max_weekend_shifts_per_month</td>
                                <td class="editable" data-param-type="rest_time_control" data-param-name="max_weekend_shifts_per_month">
                                    <span class="param-value">{{ rest_time_control.max_weekend_shifts_per_month }}</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ rest_time_control.max_weekend_shifts_per_month }}" min="0" max="10">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>每月最多的周末班次数</td>
                            </tr>
                            <tr>
                                <td>balance_shift_distribution</td>
                                <td class="editable" data-param-type="rest_time_control" data-param-name="balance_shift_distribution">
                                    <span class="param-value">{{ rest_time_control.balance_shift_distribution }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" value="{{ rest_time_control.balance_shift_distribution }}">
                                            <option value="true" {% if rest_time_control.balance_shift_distribution %}selected{% endif %}>True</option>
                                            <option value="false" {% if not rest_time_control.balance_shift_distribution %}selected{% endif %}>False</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>是否平衡分配不同类型的班次</td>
                            </tr>
                            <tr>
                                <td>rotation_pattern</td>
                                <td class="editable" data-param-type="rest_time_control" data-param-name="rotation_pattern">
                                    <span class="param-value">{{ rest_time_control.rotation_pattern }}</span>
                                    <div class="edit-form">
                                        <select class="form-select" value="{{ rest_time_control.rotation_pattern }}">
                                            <option value="forward" {% if rest_time_control.rotation_pattern == 'forward' %}selected{% endif %}>forward</option>
                                            <option value="backward" {% if rest_time_control.rotation_pattern == 'backward' %}selected{% endif %}>backward</option>
                                            <option value="random" {% if rest_time_control.rotation_pattern == 'random' %}selected{% endif %}>random</option>
                                        </select>
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                                <td>轮班模式：'forward'(顺时针), 'backward'(逆时针), 'random'(随机)</td>
                            </tr>
                        </tbody>
                    </table>
                </div>

                <div class="param-section">
                    <h5>班次转换休息时间</h5>
                    <table class="table param-table">
                        <thead>
                            <tr>
                                <th>转换类型</th>
                                <th>休息时间</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>班次1 → 班次2</td>
                                <td class="editable" data-param-type="rest_time_control" data-param-name="shift_transition_rest.morning_shift_to_afternoon_shift">
                                    <span class="param-value">{{ rest_time_control.shift_transition_rest.morning_shift_to_afternoon_shift }}小时</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ rest_time_control.shift_transition_rest.morning_shift_to_afternoon_shift }}" min="0" max="24">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>班次2 → 班次3</td>
                                <td class="editable" data-param-type="rest_time_control" data-param-name="shift_transition_rest.afternoon_shift_to_night_shift">
                                    <span class="param-value">{{ rest_time_control.shift_transition_rest.afternoon_shift_to_night_shift }}小时</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ rest_time_control.shift_transition_rest.afternoon_shift_to_night_shift }}" min="0" max="24">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>班次3 → 班次1</td>
                                <td class="editable" data-param-type="rest_time_control" data-param-name="shift_transition_rest.night_shift_to_morning_shift">
                                    <span class="param-value">{{ rest_time_control.shift_transition_rest.night_shift_to_morning_shift }}小时</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ rest_time_control.shift_transition_rest.night_shift_to_morning_shift }}" min="0" max="24">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>班次1 → 班次3</td>
                                <td class="editable" data-param-type="rest_time_control" data-param-name="shift_transition_rest.morning_shift_to_night_shift">
                                    <span class="param-value">{{ rest_time_control.shift_transition_rest.morning_shift_to_night_shift }}小时</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ rest_time_control.shift_transition_rest.morning_shift_to_night_shift }}" min="0" max="24">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>班次2 → 班次1</td>
                                <td class="editable" data-param-type="rest_time_control" data-param-name="shift_transition_rest.afternoon_shift_to_morning_shift">
                                    <span class="param-value">{{ rest_time_control.shift_transition_rest.afternoon_shift_to_morning_shift }}小时</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ rest_time_control.shift_transition_rest.afternoon_shift_to_morning_shift }}" min="0" max="24">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>班次3 → 班次2</td>
                                <td class="editable" data-param-type="rest_time_control" data-param-name="shift_transition_rest.night_shift_to_afternoon_shift">
                                    <span class="param-value">{{ rest_time_control.shift_transition_rest.night_shift_to_afternoon_shift }}小时</span>
                                    <div class="edit-form">
                                        <input type="number" class="form-control" value="{{ rest_time_control.shift_transition_rest.night_shift_to_afternoon_shift }}" min="0" max="24">
                                        <div class="btn-group">
                                            <button class="btn btn-sm btn-success save-btn"><i class="fas fa-check"></i></button>
                                            <button class="btn btn-sm btn-danger cancel-btn"><i class="fas fa-times"></i></button>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="tab-pane fade" id="json" role="tabpanel">
                <div class="param-section mt-3">
                    <h5>通用参数（JSON格式）</h5>
                    <div class="json-display">{{ params|tojson(indent=2) }}</div>
                </div>

                <div class="param-section">
                    <h5>班次配置（JSON格式）</h5>
                    <div class="json-display">{{ shift_config|tojson(indent=2) }}</div>
                </div>

                <div class="param-section">
                    <h5>三班制排班参数（JSON格式）</h5>
                    <div class="json-display">{{ three_shift_params|tojson(indent=2) }}</div>
                </div>

                <div class="param-section">
                    <h5>班制控制参数（JSON格式）</h5>
                    <div class="json-display">{{ shift_control|tojson(indent=2) }}</div>
                </div>

                <div class="param-section">
                    <h5>班制模式配置（JSON格式）</h5>
                    <div class="json-display">{{ shift_mode_config|tojson(indent=2) }}</div>
                </div>

                <div class="param-section">
                    <h5>休息时间控制参数（JSON格式）</h5>
                    <div class="json-display">{{ rest_time_control|tojson(indent=2) }}</div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
    $(document).ready(function() {
        // 点击参数值显示编辑表单
        $('.editable').on('click', function() {
            // 隐藏所有其他编辑表单
            $('.edit-form').hide();
            $('.param-value').show();

            // 显示当前编辑表单
            $(this).find('.param-value').hide();
            $(this).find('.edit-form').show();
            $(this).find('input, select').focus();
        });

        // 点击保存按钮保存参数
        $('.save-btn').on('click', function(e) {
            e.stopPropagation();

            const $editableCell = $(this).closest('.editable');
            const paramType = $editableCell.data('param-type');
            const paramName = $editableCell.data('param-name');
            let paramValue;

            // 获取参数值
            const $input = $editableCell.find('input, select');
            if ($input.prop('multiple')) {
                // 多选列表
                paramValue = $input.val().join(',');
            } else {
                // 单选或输入框
                paramValue = $input.val();
            }

            // 发送AJAX请求保存参数
            $.ajax({
                url: '/page/config_params_page',
                type: 'POST',
                data: {
                    param_type: paramType,
                    param_name: paramName,
                    param_value: paramValue
                },
                success: function(response) {
                    if (response.success) {
                        // 更新参数值
                        if ($input.prop('multiple')) {
                            // 多选列表
                            $editableCell.find('.param-value').text($input.val().join(', '));
                        } else {
                            // 单选或输入框
                            $editableCell.find('.param-value').text(paramValue);
                        }

                        // 隐藏编辑表单
                        $editableCell.find('.edit-form').hide();
                        $editableCell.find('.param-value').show();

                        // 显示成功消息
                        showToast('success', response.message);

                        // 如果是班制模式参数，更新班次显示
                        if (paramType === 'three_shift_params' && paramName === 'shift_mode') {
                            updateShiftDisplay(parseInt(paramValue));
                        }
                    } else {
                        // 显示错误消息
                        showToast('danger', response.message);
                    }
                },
                error: function() {
                    // 显示错误消息
                    showToast('danger', '保存参数失败，请重试');
                }
            });
        });

        // 点击取消按钮取消编辑
        $('.cancel-btn').on('click', function(e) {
            e.stopPropagation();

            const $editableCell = $(this).closest('.editable');

            // 隐藏编辑表单
            $editableCell.find('.edit-form').hide();
            $editableCell.find('.param-value').show();
        });

        // 按下回车键保存参数
        $('.edit-form input, .edit-form select').on('keypress', function(e) {
            if (e.which === 13) {
                e.preventDefault();
                $(this).closest('.edit-form').find('.save-btn').click();
            }
        });

        // 按下ESC键取消编辑
        $('.edit-form input, .edit-form select').on('keydown', function(e) {
            if (e.which === 27) {
                e.preventDefault();
                $(this).closest('.edit-form').find('.cancel-btn').click();
            }
        });

        // 点击页面其他地方取消编辑
        $(document).on('click', function(e) {
            if (!$(e.target).closest('.editable').length) {
                $('.edit-form').hide();
                $('.param-value').show();
            }
        });

        // 更新班次显示
        function updateShiftDisplay(shiftMode) {
            // 根据班制模式显示/隐藏班次
            if (shiftMode === 1) {
                $('#shift1Section').show();
                $('#shift2Section').hide();
                $('#shift3Section').hide();
            } else if (shiftMode === 2) {
                $('#shift1Section').show();
                $('#shift2Section').show();
                $('#shift3Section').hide();
            } else if (shiftMode === 3) {
                $('#shift1Section').show();
                $('#shift2Section').show();
                $('#shift3Section').show();
            }
        }

        // 显示消息提示
        function showToast(type, message) {
            const toast = `
                <div class="toast" role="alert" aria-live="assertive" aria-atomic="true" data-bs-delay="3000">
                    <div class="toast-header bg-${type} text-white">
                        <strong class="me-auto">提示</strong>
                        <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
                    </div>
                    <div class="toast-body">
                        ${message}
                    </div>
                </div>
            `;

            $('.toast-container').append(toast);
            const toastElement = $('.toast').last();
            const bsToast = new bootstrap.Toast(toastElement);
            bsToast.show();

            // 自动移除消息
            toastElement.on('hidden.bs.toast', function() {
                $(this).remove();
            });
        }

        // 初始化时根据班制模式显示/隐藏班次
        const currentShiftMode = parseInt($('[data-param-type="three_shift_params"][data-param-name="shift_mode"] .param-value').text());
        updateShiftDisplay(currentShiftMode);
    });
</script>
{% endblock %}